import request from '../utils/request';
import { PAGE_SIZE } from '../constants';

export function fetch() {
  return request(`/api/restricted/Menu/All`);
}

export function menuTreeNodeFetch({ permID }) {
  var data = new FormData()
  data.append('permID', permID)
  return request(`/api/restricted/Menu/TreeNode`, {
    method: 'POST',
    body: data
  });
}

export function menuUserTreeNodeFetch({ permID }) {
  var data = new FormData()
  data.append('permID', permID)
  return request(`/api/restricted/Menu/TreeNode/User`, {
    method: 'POST',
    body: data
  });
}
/**获取角色权限 */
export function CheckedRolePermsFetch({ roleID }) {
  return request(`/api/restricted/Menu/CheckedRole/perms/${roleID}`);
}
/**获取角色员工 */
export function CheckedRoleUsersFetch({ roleID }) {
  return request(`/api/restricted/Menu/CheckedRole/users/${roleID}`);
}
/**获取员工权限 */
export function CheckedUserPermsFetch({ userID }) {
  return request(`/api/restricted/Menu/CheckedUser/perms/${userID}`);
}
/**获取员工角色 */
export function CheckedUserRolesFetch({ userID }) {
  return request(`/api/restricted/Menu/CheckedUser/roles/${userID}`);
}
/**角色权限设置 */
export function rolePermsSave({ roleID, permTreeCheckedKeys, userTreeCheckedKeys }) {
  var data = new FormData()
  data.append('RolePerms', JSON.stringify(permTreeCheckedKeys))
  data.append('RoleUsers', JSON.stringify(userTreeCheckedKeys))
  return request(`/api/restricted/Menu/RolePerms/${roleID}`, {
    method: 'POST',
    body: data
  });
}
/**用户权限设置 */
export function userPermsSave({ userID, permUserCheckedKeys, roleTreeCheckedKeys }) {
  var data = new FormData()
  data.append('UserPerms', JSON.stringify(permUserCheckedKeys))
  data.append('UserRoles', JSON.stringify(roleTreeCheckedKeys))
  return request(`/api/restricted/Menu/UserPerms/${userID}`, {
    method: 'POST',
    body: data
  });
}

export function changePassword({ oldPassword, newPassword }) {
  var data = new FormData()
  data.append('OldPassword', oldPassword)
  data.append('NewPassword', newPassword)
  return request(`/api/restricted/Menu/Password`, {
    method: 'POST',
    body: data
  });
}

export function initPasswordFetch({ userIDs }) {
  var data = new FormData()
  data.append('UserIDs', JSON.stringify(userIDs))
  return request(`/api/restricted/Menu/InitPassword`, {
    method: 'POST',
    body: data
  });
}

export function StopUsing({ userIDs, status }) {
  var data = new FormData()
  data.append('UserIDs', JSON.stringify(userIDs))
  data.append('status', JSON.stringify(status))
  return request(`/api/restricted/Menu/StopUsing`, {
    method: 'POST',
    body: data
  });
}

export function SetUsingGhr({ userIDs, status }) {
  var data = new FormData()
  data.append('UserIDs', JSON.stringify(userIDs))
  data.append('status', JSON.stringify(status))
  return request(`/api/restricted/Menu/SetUsingGhr`, {
    method: 'POST',
    body: data
  });
}



export function GetSysUserName({ name }) {
  var data = new FormData()
  data.append('name', JSON.stringify(name))
  return request(`/api/restricted/Menu/GetSysUserName`, {
    method: 'POST',
    body: data
  });
}

